class RubricaController {
    
    def index = { redirect(action:list,params:params) }

    // the delete, save and update actions only accept POST requests
    def allowedMethods = [delete:'POST', save:'POST', update:'POST']

    def list = {
        if(!params.max) params.max = 10
        [ rubricaInstanceList: Rubrica.list( params ) ]
    }

    def show = {
        def rubricaInstance = Rubrica.get( params.id )

        if(!rubricaInstance) {
            flash.message = "Rubrica not found with id ${params.id}"
            redirect(action:list)
        }
        else { return [ rubricaInstance : rubricaInstance ] }
    }

    def delete = {
        def rubricaInstance = Rubrica.get( params.id )
        if(rubricaInstance) {
            rubricaInstance.delete()
            flash.message = "Rubrica ${params.id} deleted"
            redirect(action:list)
        }
        else {
            flash.message = "Rubrica not found with id ${params.id}"
            redirect(action:list)
        }
    }

    def edit = {
        def rubricaInstance = Rubrica.get( params.id )

        if(!rubricaInstance) {
            flash.message = "Rubrica not found with id ${params.id}"
            redirect(action:list)
        }
        else {
            return [ rubricaInstance : rubricaInstance ]
        }
    }

    def update = {
        def rubricaInstance = Rubrica.get( params.id )
        if(rubricaInstance) {
            rubricaInstance.properties = params
            if(!rubricaInstance.hasErrors() && rubricaInstance.save()) {
                flash.message = "Rubrica ${params.id} updated"
                redirect(action:show,id:rubricaInstance.id)
            }
            else {
                render(view:'edit',model:[rubricaInstance:rubricaInstance])
            }
        }
        else {
            flash.message = "Rubrica not found with id ${params.id}"
            redirect(action:edit,id:params.id)
        }
    }

    def create = {
        def rubricaInstance = new Rubrica()
        rubricaInstance.properties = params
        return ['rubricaInstance':rubricaInstance]
    }

    def save = {
        def rubricaInstance = new Rubrica(params)
        if(!rubricaInstance.hasErrors() && rubricaInstance.save()) {
            flash.message = "Rubrica ${rubricaInstance.id} created"
            redirect(action:show,id:rubricaInstance.id)
        }
        else {
            render(view:'create',model:[rubricaInstance:rubricaInstance])
        }
    }
}
